﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxCallback;
using DevExpress.Web.ASPxGridView;

public partial class NPS_app_Marketing_ViewRecord : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            search("all");
        }
        else
        {
            bindit();
        }
    }

    protected void bindit()
    {
        dgMarketing.DataSource = (List<Entities.NPSMarketingActivity>)Session["mvrData"];
        dgMarketing.DataBind();
    }

    protected void dgMarketing_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
    {
        if (e.Parameters.ToUpper().StartsWith("SELECT"))
        {
            HandleSelect(e.Parameters);
        }
        else if (e.Parameters.ToUpper().StartsWith("CHANGE"))
        {
            HandleRefresh();
        }
    }
    protected void cbkMarketing_Callback(object sender, CallbackEventArgs e)
    {

    }

    protected void HandleSelect(String sxParameter)
    {

    }


    protected void HandleRefresh()
    {
        dgMarketing.DataSource = null;
        dgMarketing.DataBind();
        dgMarketing.Selection.UnselectAll();
    }

    protected void search(string opt)
    {
        
        string name, type;
        DateTime start, end;
        start = txtStartDate.SelectedDate;
        end = txtEndDate.SelectedDate;
        name = string.Empty;
        type = string.Empty;
        Controller.NPSMarketingActivityController mac = new Controller.NPSMarketingActivityController();
        List<Entities.NPSMarketingActivity> marketing;
        if (opt == "all")
        { marketing=mac.NPSDetailedMarketingActivityList;}
        else { marketing= mac.getNPSMarketingActivityList(name, type, start, end);}
        Session["mvrData"] = marketing;
        dgMarketing.DataSource = marketing;
        dgMarketing.DataBind();
    }


    protected void btnFilter_Click(object sender, EventArgs e)
    {
        search("filter");
    }
    protected void btnAll_Click(object sender, EventArgs e)
    {

        search("all");
    }
}
